//
//  ReplacePhoneViewController.m
//  WBBaseProject
//
//  Created by 吴斌 on 2018/4/2.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "ReplacePhoneViewController.h"
#import "InputTwoView.h"
#import "PhoneRegisterViewController.h"
#import "FaceVerifiViewController.h"
#import "ReplacePhoneCodeViewController.h"
@interface ReplacePhoneViewController ()
@property (nonatomic,strong) UITextField *phoneTF;
@end

@implementation ReplacePhoneViewController

#pragma mark - 生命周期 Life Circle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"更换手机号";
    [self setUpUI];
}

- (void)setUpUI
{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    scrollView.contentSize = CGSizeMake(kScreenWidth, kScreenHeight + 1);
    scrollView.backgroundColor = WB_RGBColor(240, 240, 240);
    [self.view addSubview:scrollView];
    
    //+86
    InputTwoView *phoneView = [[NSBundle mainBundle] loadNibNamed:@"InputTwoView" owner:self options:nil].firstObject;
    phoneView.titleLb.text = @"+86";
    phoneView.frame = CGRectMake(0, 10, kScreenWidth, 45);
    phoneView.inputTF.placeholder = @"请输入您的新手机号";
    phoneView.inputTF.keyboardType = UIKeyboardTypePhonePad;
    _phoneTF = phoneView.inputTF;
    [scrollView addSubview:phoneView];
    
  
    //提示
//    UILabel *tipLb = [[UILabel alloc] initWithFrame:CGRectMake(15, phoneView.mm_bottom + 15, kScreenWidth - 30, 20)];
//    tipLb.text = @"一个手机号只能作为一个账号的登录名";
//    tipLb.font = [UIFont systemFontOfSize:12];
//    tipLb.textColor = WB_RGBColor(153, 153, 153);
//    [scrollView addSubview:tipLb];
    
    //确定
    UIButton *sureBtn = [Factory customButtonWithTitle:@"下一步"];
    sureBtn.tag = 1000;
    sureBtn.frame = CGRectMake(60, phoneView.mm_bottom + 25, kScreenWidth - 120, 60);
    [sureBtn addTarget:self action:@selector(clickMethod:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:sureBtn];
    
    //提示
    UILabel *tipLb = [[UILabel alloc] initWithFrame:CGRectMake(0, sureBtn.mm_bottom + 5, kScreenWidth, 20)];
    tipLb.text = @"一个手机号只能作为一个账号的登录";
    tipLb.textAlignment = NSTextAlignmentCenter;
    tipLb.font = [UIFont systemFontOfSize:12];
    tipLb.textColor = WB_RGBColor(153, 153, 153);
    [scrollView addSubview:tipLb];
}

- (void)clickMethod:(UIButton *)sender
{
//    PhoneRegisterViewController *vc = [[PhoneRegisterViewController alloc] init];
//    [self.navigationController pushViewController:vc animated:YES];
//    return;
    
//    FaceVerifiViewController *vc = [[FaceVerifiViewController alloc] init];
//    [self.navigationController pushViewController:vc animated:YES];
//    return;
    
    
    
    //WB_WeakSelf(self)
    if (WB_IsNilString(_phoneTF.text)) {
        [NSObject wb_showAlertWithTitle:@"账号不能为空"];
        return;
    }else if (![Factory isPhoneNumber:_phoneTF.text]){
        [NSObject wb_showAlertWithTitle:@"请输入正确格式的手机号"];
        return;
    }else if (WB_IsEquallString(_phoneTF.text, [[NSUserDefaults standardUserDefaults] objectForKey:AppUserPhone])) {
        PhoneRegisterViewController *vc = [[PhoneRegisterViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        
        ReplacePhoneCodeViewController *vc = [[ReplacePhoneCodeViewController alloc] init];
        vc.phone = _phoneTF.text;
        [self.navigationController pushViewController:vc animated:YES];
    }

}

@end
